<?
 class log extends DM{
//
//
// 
// 
// 
// VERSION: 
// AUTHOR: bugz
// DATE: 24.12.2006
// 


// VARIABLE DECLARATION
	var $id_log = "";
	var $id_site = "";
	var $id_uagent = "";
	var $id_charset = "";
	var $id_lang = "";
	var $id_page = "";
	var $id_query = "";
	var $ip4 = "";
	var $ip6 = "";
	var $timestamp = "";

	var $debugging=false;

	var $lista = "";


// METHOD DECLARATION

//DEBUG METHOD
	function debug($result,$operation=""){
		if ($result){
			if ($this->debugging){
				echo "<div style='font-size:10px;font-family:arial,sans;color:#FFFFFF;background-color:#008800'>OK: ";
				echo strtoupper($this->db_type)."($operation) - [No errors computed] ";
				echo "</div>";
			}
			return true;
		}else{
			if ($this->debugging){
				echo "<div style='font-family:arial,sans;color:#FFFFFF;background-color:#ff0000;font-size:10px;'>ERROR: ";
				echo strtoupper($this->db_type)."($operation) - [".$this->db->errDesc."] ".$this->db->errDesc;
				echo "</div>";
			}
			return false;
		}
		
	}

//CONSTRUCTOR METHOD
	function log(){
		//LOAD THE DATABSE CLASS
		$this->loadClass('database','database');

		//INITIALIZE THE VARIABLES
		$this->id_log = "";
		$this->id_site = "";
		$this->id_uagent = "";
		$this->id_charset = "";
		$this->id_lang = "";
		$this->id_page = "";
		$this->id_query = "";
		$this->ip4 = "";
		$this->ip6 = "";
		$this->timestamp = "";
		$this->lista = array();

	}

//GET METHODS
//
//
//
	function getList(){

		//SQL STRING
		$sql="SELECT id_log FROM tbl_log WHERE 1";
		$db= new database();
		$db->debugging=$this->debugging;
		if ($db->connect()){
			if ($db->fetch($sql)){
				$this->lista=$db->resultArray;
				return $this->debug(true,'get_list');
			}else{
				$this->errorReport("Error in the select",$sql);
				return $this->debug(false,"get_List - $sql");
			}
		}else{
			$this->errorReport("Could not conncet to the database",$db);
			return $this->debug(false,'get_list');
		}
	}

	function getById(){
		if ($this->id_log!=""){
			$sql = "select * from tbl_log where id_log='$this->id_log'";
			$db= new database();
			$db->debugging=$this->debugging;
			if ($db->connect()){
				if ($db->fetch($sql)){
					if (count($db->resultArray)==1){
						$this->id_log = $db->resultArray[0]["id_log"];
						$this->id_site = $db->resultArray[0]["id_site"];
						$this->id_uagent = $db->resultArray[0]["id_uagent"];
						$this->id_charset = $db->resultArray[0]["id_charset"];
						$this->id_lang = $db->resultArray[0]["id_lang"];
						$this->id_page = $db->resultArray[0]["id_page"];
						$this->id_query = $db->resultArray[0]["id_query"];
						$this->ip4 = $db->resultArray[0]["ip4"];
						$this->ip6 = $db->resultArray[0]["ip6"];
						$this->timestamp = $db->resultArray[0]["timestamp"];
						return true;
					}else{
						$this->errorReport("Error too many results.",$sql);
						return false;
					}
				}else{
					$this->errorReport("Error in the select",$sql);
					return false;
				}
			}else{
				$this->errorReport("Could not conncet to the database",$db);
				return false;
			}
		}
	}
		function save(){
			if ($this->id_log==""){
				//insert
				$sql = "";
				$sql .= "INSERT INTO tbl_log(";
				$sql .= " id_log";
				$sql .= ", id_site";
				$sql .= ", id_uagent";
				$sql .= ", id_charset";
				$sql .= ", id_lang";
				$sql .= ", id_page";
				$sql .= ", id_query";
				$sql .= ", ip4";
				$sql .= ", ip6";
				$sql .= ", timestamp";
				$sql .= ") VALUES (";
				$sql .= " ''";
				$sql .= ", '$this->id_site'";
				$sql .= ", '$this->id_uagent'";
				$sql .= ", '$this->id_charset'";
				$sql .= ", '$this->id_lang'";
				$sql .= ", '$this->id_page'";
				$sql .= ", '$this->id_query'";
				$sql .= ", '$this->ip4'";
				$sql .= ", '$this->ip6'";
				$sql .= ", NOW()";
				$sql .= ")";
			}else{
				//update
				$sql = "";
				$sql .= "UPDATE tbl_log SET";
				$sql .= " id_site";
				$sql .= " = '$this->id_site'";
				$sql .= ", id_uagent";
				$sql .= " = '$this->id_uagent'";
				$sql .= ", id_charset";
				$sql .= " = '$this->id_charset'";
				$sql .= ", id_lang";
				$sql .= " = '$this->id_lang'";
				$sql .= ", id_page";
				$sql .= " = '$this->id_page'";
				$sql .= ", id_query";
				$sql .= " = '$this->id_query'";
				$sql .= ", ip4";
				$sql .= " = '$this->ip4'";
				$sql .= ", ip6";
				$sql .= " = '$this->ip6'";
				$sql .= ", timestamp";
				$sql .= " = '$this->timestamp'";
				$sql .= " where ";
				$sql .= " id_log = '".$this->id_log."'";
			}
			$db= new database();
			$db->debugging=$this->debugging;
			if ($db->connect()){
				if ($db->execute($sql)){
					return true;
				}else{
					$this->errorReport("Error in the select",$sql);
					return false;
				}
			}else{
				$this->errorReport("Could not conncet to the database",$db);
				return false;
			}
	}
	function delete(){
		$sql="DELETE FROM tbl_log WHERE id_log='$this->id_log'";
		$db= new database();
		$db->debugging=$this->debugging;
		if ($db->connect()){
			if ($db->execute($sql)){
				return true;
			}else{
				$this->errorReport("Error in the SQL:<BR>",$sql);
				return false;
			}
		}else{
			$this->errorReport("Error in the Connect");
			return false;
		}
	}


}
?>
